package com.gson.token.tokenStorager.tokenStoragerImpl;

import cc.bluemc.platform.springUtil.SpringConfigUtil;
import com.gson.token.Token;
import com.gson.token.tokenStorager.TokenStorager;
import org.springframework.data.redis.core.BoundValueOperations;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.concurrent.TimeUnit;

/**
 * @Company 陕西识代运筹信息科技股份有限公司
 * @Discription
 * @Author houfengli
 * @CreateDate 2017/2/17 15:43
 * @Version 1.0
 */
public class TokenStoragerRides implements TokenStorager {

    private RedisTemplate<String,String> redisTemplate= (RedisTemplate) SpringConfigUtil.getBean("redisTemplate");

    @Override
    public void cacheToken(Token token) {
        BoundValueOperations<String,String> ops = redisTemplate.boundValueOps(token.getKey());
        ops.set(token.getValue());
        ops.expire(token.getCacheTime(), TimeUnit.SECONDS);
    }

    @Override
    public String getToken(String key) {
        BoundValueOperations<String,String> ops = redisTemplate.boundValueOps(key);
        return ops.get();
    }
}
